package com.zlq.cn.test;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;

import java.nio.charset.StandardCharsets;

/**
 * 请求加解密工具类
 *
 * @date 2022/1/18
 */
public class RequestAesUtil {

    public static String decrypt(String encryptData, String key) {
        AES aes = SecureUtil.aes(key.getBytes(StandardCharsets.UTF_8));
        return aes.decryptStr(encryptData, CharsetUtil.CHARSET_UTF_8);
    }

    public static String encrypt(String data, String key) {
        AES aes = SecureUtil.aes(key.getBytes(StandardCharsets.UTF_8));
        return aes.encryptBase64(data.getBytes(StandardCharsets.UTF_8));
    }

    public static void main(String[] args) {
        String key = "7F3E4A109890FF6A";
        String data = "{\"imei\":\"23134654978\",\"isBeingTraced\":\"0\",\"isEmulator\":\"0\",\"isRoot\":\"0\",\"isVirtual\":\"0\",\"isVpn\":\"0\",\"isXposed\":\"0\",\"password\":\"e10adc3949ba59abbe56e057f20f883e\",\"phone\":\"17620410531\"}";

        String encrypt = encrypt(data, key);
        System.out.println(encrypt);
//        H5zETVQ2l2N+VHwwW12FuD7MP6yFPoTcF2IJGH8O+XJ8p2qWSRK7Xdbt7nO98uBeDNpvNPCe7vRoW3u/u7vKxAsSs4xz8qIlFx3cWa4+qk4f8ZhoTOiomQacnV/mdvLjEtWVzHgx6djTv9o3esaSEVzXDDHTvfc7DMpM5aojjjChGcgG1WGOSL6qYk4BlnYObjIubTLac4LmAxOwDm3fZFP70ggrLA6ep1EbAll9Ib7zH6iZCOkUKLLz0qc9mjm7
//        H5zETVQ2l2N+VHwwW12FuD7MP6yFPoTcF2IJGH8O+XJ8p2qWSRK7Xdbt7nO98uBeDNpvNPCe7vRoW3u/u7vKxAsSs4xz8qIlFx3cWa4+qk4f8ZhoTOiomQacnV/mdvLjEtWVzHgx6djTv9o3esaSEVzXDDHTvfc7DMpM5aojjjChGcgG1WGOSL6qYk4BlnYObjIubTLac4LmAxOwDm3fZFP70ggrLA6ep1EbAll9Ib7zH6iZCOkUKLLz0qc9mjm7
        System.out.println(decrypt(encrypt,key));
    }

}
